<template>
    <div>
<!--       面包屑-->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{path:'/home'}">首页</el-breadcrumb-item>
            <el-breadcrumb-item><a href="/orders">订单管理</a></el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
<!--        卡片区-->
        <el-card>
            <el-row>
<!--                搜索-->
                <el-row :span="6">
                    <el-input
                            v-model="queryInfo.query"
                            clearable
                            @clear="getOrders"
                            placeholder="请输入搜索内容">
                        <template #append>
                            <el-button icon="el-icon-search" @click="getOrders"></el-button>
                        </template>
                    </el-input>
                </el-row>
<!--                列表-->
                <el-table :data="orderList" stripe border>
                    <el-table-column type="index"></el-table-column>
                    <el-table-column label="订单编号" min-width="150" prop="order_number" align="center"></el-table-column>
                    <el-table-column label="订单价格" min-width="50" prop="order_price" align="center"></el-table-column>
                    <el-table-column label="是否付款" min-width="80" align="center">
                        <template #default="scope">
                            <el-tag v-if="scope.row.pay_status==='0'" type="danger">未付款</el-tag>
                            <el-tag v-if="scope.row.pay_status==='1'" type="success">已付款</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="是否发货" min-width="50" prop="is_send" align="center"></el-table-column>
                    <el-table-column label="下单时间" min-width="100" align="center">
                        <template #default="scope">
                            {{formatDate(scope.row.create_time)}}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" min-width="120" align="center">
                        <template #default="scope">
                            <el-tooltip effect="dark" content="修改地址" placement="top">
                                <el-button type="primary" size="mini"
                                           @click="showEditAddressDialog"
                                           icon="el-icon-edit"></el-button>
                            </el-tooltip>
                            <el-tooltip effect="dark" content="查看物流" placement="top">
                                <el-button type="success" size="mini"
                                           @click="showProgressDialog(scope.row.order_id)"
                                           icon="el-icon-location-outline"></el-button>
                            </el-tooltip>
                        </template>
                    </el-table-column>
                </el-table>
            </el-row>
<!--            分页-->
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="queryInfo.pagenum"
                    :page-sizes="[10,15,20,30]"
                    layout="total,sizes,prev,pager,next,jumper"
                    :pagesize="queryInfo.pagesize"
                    :total="total"></el-pagination>
        </el-card>
<!--       修改地址dialog-->
        <el-dialog
                v-model="editAddressDialogVisible"
                title="修改地址">
            <el-form :model="editAddressForm"
                     :rules="editAddressFormRules"
                     ref = 'editAddressFormRef'
                     label-width="100px">
                <el-form-item label="省市县/区" prop="address1">
                    <el-cascader
                            style="width:100%"
                            v-model="editAddressForm.address1"
                            :props="cascaderProps"
                            :options="cityData"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="editAddressForm.address2" placeholder="请输入详细地址"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <el-button @click="closeEditAddressDialog">取消</el-button>
                <el-button type="primary">确定</el-button>
            </template>
        </el-dialog>
<!--        物流信息-->
        <el-dialog
                title="物流信息"
                :before-close="closeProgressDialog"
                v-model="progressDialogVisible">
<!--            时间线-->
            <el-timeline>
                <el-timeline-item
                        v-for="(item, index) in progressData"
                        :timestamp="item.time"
                        :key="index">
                    {{item.context}}
                </el-timeline-item>
            </el-timeline>
        </el-dialog>
    </div>
</template>

<script>
    import timeMixin from "../../mixin/timeMixin";
    import {cityData} from '../../assets/citydata.js'
  export default {
    name: "OrderList",
    data(){
      return {
        queryInfo:{
          query:'',//搜索关键字
          pagenum:1,
          pagesize:10,
        },
        orderList:[],//订单数据
        total:0,
        editAddressDialogVisible:false,//修改地址dialog
        editAddressForm:{
          address1:[],
          address2:'',
        },
        editAddressFormRules:{
          address1: [{required:true,message:'请选择省市县',trigger:'blur'}],
          address2: [{required:true,message:'请填写详细地址',trigger:'blur'}],
        },
        cityData:cityData,
        cascaderProps:{//级联选择器配置项
          value:'id',
          label:'name',
          children:'sub',
        },
        progressDialogVisible:false,//物流进度
        orderId:'',//订单id,查看此物流
        progressData:[
          {
            "time": "2018-05-10 09:39:00",
            "ftime": "2018-05-10 09:39:00",
            "context": "已签收,感谢使用顺丰,期待再次为您服务",
            "location": ""
          },
          {
            "time": "2018-05-10 08:23:00",
            "ftime": "2018-05-10 08:23:00",
            "context": "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
            "location": ""
          },
          {
            "time": "2018-05-10 07:32:00",
            "ftime": "2018-05-10 07:32:00",
            "context": "快件到达 [北京海淀育新小区营业点]",
            "location": ""
          },
          {
            "time": "2018-05-10 02:03:00",
            "ftime": "2018-05-10 02:03:00",
            "context": "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
            "location": ""
          },
          {
            "time": "2018-05-09 23:05:00",
            "ftime": "2018-05-09 23:05:00",
            "context": "快件到达 [北京顺义集散中心]",
            "location": ""
          },
          {
            "time": "2018-05-09 21:21:00",
            "ftime": "2018-05-09 21:21:00",
            "context": "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
            "location": ""
          },
          {
            "time": "2018-05-09 13:07:00",
            "ftime": "2018-05-09 13:07:00",
            "context": "顺丰速运 已收取快件",
            "location": ""
          },
          {
            "time": "2018-05-09 12:25:03",
            "ftime": "2018-05-09 12:25:03",
            "context": "卖家发货",
            "location": ""
          },
          {
            "time": "2018-05-09 12:22:24",
            "ftime": "2018-05-09 12:22:24",
            "context": "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
            "location": ""
          },
          {
            "time": "2018-05-08 21:36:04",
            "ftime": "2018-05-08 21:36:04",
            "context": "商品已经下单",
            "location": ""
          }
        ],//物流详情
      }
    },
    mixins:[timeMixin],
    created() {
      this.getOrders();
    },
    methods:{
      async getOrders(){
        const {data:res} = await this.$http.get(`/orders`,{params:this.queryInfo});
        if(res.meta.status !== 200){
          return this.$message.error(res.meta.msg);
        }
        console.log(res);
        this.orderList = res.data.goods;
        this.total = res.data.total;
      },
      //分页控制
      handleSizeChange(val){
        this.queryInfo.pagesize = val;
        this.getOrders();
      },
      handleCurrentChange(val) {
        this.queryInfo.pagenum = val;
        this.getOrders();
      },
      //修改地址
      showEditAddressDialog(){
        this.editAddressDialogVisible = true;
      },
      closeEditAddressDialog(){
        this.editAddressDialogVisible = false;
        this.$refs.editAddressFormRef.resetFields();
      },
      //物流进度
      showProgressDialog(id){
        this.progressDialogVisible = true;
        this.orderId = id;
        //console.log(id)
        //this.getOrderProgressById();
      },
      closeProgressDialog(){
        this.progressDialogVisible = false;
        this.orderId = '';
        //this.progressData = [];
      },
      //获取物流信息
      // async getOrderProgressById(){
      //   const {data:res} = await this.$http.get(`/kuaidi/1106975712662`);
      //   console.log(res);
      //   if(res.meta.status !== 200){
      //     return this.$message.error("获取物流信息失败！");
      //   }
      //   this.progressData = res.data;
      // }
    },

  }
</script>

<style scoped>

</style>
